|
|
|
|
|
|
|
On Error Resume Next ' Bad DLL calling convention occurs here!
' AND WE DON'T CARE!!!
res = cpuspeed(freq, 0) ' Always use zero here
lstDisplay.AddItem "Raw CPU Speed: " & freq.raw_freq & " Mhz"
lstDisplay.AddItem "Normalized CPU Speed: " & freq.norm_freq _
& " Mhz"
End Sub |
|
|
|
|
|
|
|
|
This solution won't work for structures that are 8 bytes or shorter. In those cases, the C compiler is smart enough to transfer the data in registers. |
|
|
|
|
|
|
|
|
How can you handle these smaller structures? |
|
|
|
|
|
|
|
|
The trick is to set the Visual Basic declaration to return a Currency value. The Currency value just happens to be 8 bytes. You can then copy the data from a temporary currency value into a structure of the correct type. |
|
|
|
|
|
|
|
|
Here's a short code fragment that shows how it's done: |
|
|
|
|
|
|
|
|
Private Declare Function Test Lib "mylib" ( ) As Currency
Private Sub Command2_Click()
Dim m As mystruct
Dim c As Currency
c = Test( ) ' Store the result in a temporary currency value
' Then copy the data from the currency variable into the structure.
RtlMoveMemory m, c, 8
End Sub |
|
|
|
|
|